<?php
/**
 * Created by 孙洪亮.
 * 文件用途描述 :
 * Date: 2018/2/11/011
 * Time: 1:13
 */

namespace app\api\validate;


class IDCollection extends BaseValidate
{
    //定义验证规则
    protected $rule=[
        'ids'=>'require|checkIDs',
    ];
//定义验证规则,名字必须为$message
    protected $message=[
        'ids'=>'ids参数必须是以逗号为分隔符的多个正整数'
    ];

    //ids=id1,id2...
    protected function checkIDs($value){
        //将用逗号分割的字符串装转换为数组
        $values=explode(',',$value);
        if(empty($values)){
            return false;
        }
        foreach ($values as $id){
             if(!$this->isPositiveInteger($id)){
                 return false;
             }
        }
        return true;
    }
}